 REBOL [
 	Title: "ETNet Real Time Stock Quote System"
 ]
 
 stock-list: copy []
 
 data: ""
 isReload: "true"
 
 getETNetStockQuote: func [stockQuote] [
 
 	unset 'posPriceStr
 	unset 'negPriceStr
 	unset 'noChangePriceStr
 	unset 'tempPrice
 
 	etstocklink: "http://www.etnet.com.hk/www/tc/stocks/realtime/quote.php?code="	
 	
	if error? try [page: read to url! join etstocklink stockQuote] [ return "N/A" ]
	
	
 	parse page [thru <td class="QuoteRed"> copy posPriceStr thru </td>]
 	if  value? 'posPriceStr [
 		parse posPriceStr [thru "> " copy tempPrice to </td>]		
 		return to-decimal tempPrice 
 	]
 	
 	parse page [thru <td class="QuoteGreen"> copy negPriceStr thru </td>]
 	if value? 'negPriceStr
 	[ 
 		parse negPriceStr [thru "> " copy tempPrice to </td>]
 		return to-decimal tempPrice 
 	]
 	
 	parse page [thru <td class="QuoteBlack"> copy noChangePriceStr thru </td>]
 	if value? 'noChangePriceStr
 	[ 
 		parse noChangePriceStr [thru "> " copy tempPrice to </td>]
 		return to-decimal tempPrice 
 	]
 
 ]
 
 
 
 getStockPrice: func [] [
 	foreach stock stock-list[
		 	price: getETNetStockQuote stock
		 	append data (join (join stock (join " = " price)) newline)
	]
 ]
 
 
 getStockListStr: func[] [
 	unset 'temp	
	temp: make string! 100
	foreach stockcode stock-list[
		 append temp join stockcode " "
	]
	return temp
 ]
 
 poll: func [] [
 	while [ equal? isReload "true" ] [
			status/text: "Refresh start"
			show status
			startTime: now/time
			getStockPrice
			vdata/text: copy data
			show vdata
			status/text: join "Refresh Completed in " (now/time - startTime)
			show status
			wait 1
			clear data
	]
 ]
 
 lay-spec: layout [
 	style lab label right 150x30
 	style longLab label left 200x30
	style fld field 60 bold beige font-name font-fixed
	style fldPrice field 60 bold beige font-name font-fixed
 
	longLab "Current Stock List:"
	stock-list-fld: longLab
	
	vdata: area
	
	across 
	lab "Stock to add:" stockCodeAdd: fld 
	addButton: button "Add" [
		
		if none? find stock-list stockCodeAdd/text [
			alter stock-list stockCodeAdd/text
			
			stock-list-fld/text: copy getStockListStr
			stockCodeAdd/text: copy ""
			
			show stockCodeAdd
			show stock-list-fld
			
			focus stockCodeAdd
		]
	]
	return 
	
	lab "Stock to delete:" stockCodeDelete: fld 	
	removeButton: button "Remove" [
	
		if not none? find stock-list stockCodeDelete/text [
	
			alter stock-list stockCodeDelete/text
		
			stock-list-fld/text: copy getStockListStr
			stockCodeDelete/text: copy ""
			
			show stockCodeDelete
			show stock-list-fld
			
			focus stockCodeDelete
		]
	]
	return
	
	refreshButton: button "refresh" [
		hide [removeButton addButton refreshButton]
		show [stopButton]
		isReload: "true"
		poll[]
	]
	
	stopButton: button "stop" [	
		isReload: "false"
		append vdata/text "Stock Quote is Stopped"
		show [removeButton addButton vdata refreshButton]
	]
	
	status: longLab 
	
	
]
 
view lay-spec



	

   
